DateTimeAddYears

 

Creates a new DateTime object by adding or subtracting a number of years from the given DateTime object.

 

object @DateTimeAddYears(object datetime);

 

Parameters

object datetime: The created DateTime object

 

Return Value

Returns a new DateTime object after adding or subtracting the number of years.

 

Example

t = @DateTimeNow();

t = @DateTimeAddYears(t, 10);

year = @DateTimeYear(t);
month = @DateTimeMonth(t);
day = @DateTimeDay(t);
hour = @DateTimeHour(t);
minute = @DateTimeMinute(t);
second = @DateTimeSecond(t);
millisecond = @DateTimeMillisecond(t);

dow = @DateTimeDayOfWeek(t);
doy = @DateTimeDayOfYear(t);

@sprintf(buf, "%d-%d-%d %02d:%02d:%02d.%03d dow=%d,doy=%d", year, month, day, hour, minute, second, millisecond, dow, doy);
@Message(buf);

 

Description: Gets the current time, adds 10 years to create a new DateTime object, and reads each element to display it as a message.

 

Version Information

Supported Version: 10.3.0 or Higher

 

Related Helps

@DateTimeAddDays()

@DateTimeAddHours()

@DateTimeAddMilliseconds()

@DateTimeAddMinutes()

@DateTimeAddMonths()

@DateTimeAddSeconds()

@DateTimeAddYears()

@DateTimeDay()

@DateTimeDayOfWeek()

@DateTimeDayOfYear()

@DateTimeHour()

@DateTimeMillisecond()

@DateTimeMinute()

@DateTimeMonth()

@DateTimeNew()

@DateTimeNow()

@DateTimeSecond()

@DateTimeUtcNow()

@DateTimeYear()